package com.smec.moblie.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.smec.moblie.R;
import com.smec.moblie.control.EventCenter;
import com.smec.moblie.view.RippleView;

import de.greenrobot.event.EventBus;

/**
 * 侧边栏列表adapter
 *
 * @author sunyubo
 */
public class LeftItemMantrAdapter extends BaseAdapter {
    private LayoutInflater inflater;
    private String[] leftItems;
//    private Context context;

    public LeftItemMantrAdapter(Context context, String[] leftItems) {
        inflater = LayoutInflater.from(context);
        this.leftItems = leftItems;
//        this.context = context;
    }

    public void setList(String[] leftItems){
        this.leftItems = leftItems;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return leftItems.length;
    }

    @Override
    public Object getItem(int position) {
        return leftItems[position];
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @SuppressLint("InflateParams")
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view;
        if (convertView == null) {
            view = inflater.inflate(R.layout.item_left, null);
        } else {
            view = convertView;
        }
        TextView textView_item = (TextView) view
                .findViewById(R.id.textView_item);
        textView_item.setText(leftItems[position]);
        RippleView rippleView_leftlistItem = (RippleView) view.findViewById(R.id.rippleView_leftlistItem);
        rippleView_leftlistItem.setRippleDuration(100);//设置水波时间
        rippleView_leftlistItem.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {

            @Override
            public void onComplete(RippleView rippleView) {
                EventBus.getDefault().post(
                        new EventCenter.ClickMantrList(position));
            }

        });
        return view;
    }

}
